package edu.hz.util.web;

import com.alibaba.fastjson.JSON;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ApiResponse<T> {
    private String code;
    private String message;
    private T data;

    public static <T> ApiResponse<T> success(T data) {
        return new ApiResponse<>(ApiResponseCode.SUCCESS.getCode(),"success", data);
    }

    public static <T> ApiResponse<T> error(String message) {
        return new ApiResponse<>(ApiResponseCode.INTERNAL_SERVER_ERROR.getCode(), message, null);
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
